package thread.nio.base;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

/**
 * 文件映射到内存
 *
 */
public class MapperByteBuffer {
	public static void main(String[] args) throws IOException {
		RandomAccessFile raf = new RandomAccessFile("F:\\百度云\\ngrok.zip", "rw");
		FileChannel channel = raf.getChannel();
		MappedByteBuffer mbb = channel.map(FileChannel.MapMode.READ_WRITE, 0, raf.length());
		while(mbb.hasRemaining()){
			System.out.println((char)mbb.get());
		}
		//对mbb的修改就是修改文件
		mbb.put(0,(byte)98);
		raf.close();
	}
}
